package com.technology.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateFormatUsing {

	public static void main(String[] args) {
		Date date = new Date();
//		new Date(System.currentTimeMillis());
		DateFormat dateFormat = new SimpleDateFormat();
		System.out.println(dateFormat.format(date));
		
		DateFormat anotherDateFormat = new SimpleDateFormat("dd.MM.yyyy");
		System.out.println(anotherDateFormat.format(date));
		
		DateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
		System.out.println(dateTimeFormat.format(date));
		
		DateFormat fullDateFormat = DateFormat.getDateInstance(DateFormat.FULL);
		System.out.println(fullDateFormat.format(date));
		
		try {
			Date firstFebruary = anotherDateFormat.parse("01.02.2014");
			Calendar cal = Calendar.getInstance();
			cal.setTime(firstFebruary);
			
			System.out.println("Days between 2 dates: " + (Calendar.getInstance().get(Calendar.DAY_OF_YEAR) - cal.get(Calendar.DAY_OF_YEAR)));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
